﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using System;
using evt;
using DG.Tweening;
using info;
using tools;
using UnityEngine.SceneManagement;

public class ZjhView : MonoBehaviour {

	public static bool inZJHGAME = false;
	private Button UnknowBtn;
	private Text TimeTxt;
	private Text RoomNum;
	private Text GameNum;
	private Text TurnNum;
	private Text BetNum;

	public List<ZjhPlayer> list = new List<ZjhPlayer> ();
	private int PetAll = 0;
	private GameObject BetWindow;
	private GameObject BtnList = null;
	public static int UpBet = 0;
	public static long UpID;
	private long turnID = 0;
	private int turn = 0;
	public static bool Ilooked = false;
	public static bool Ifaild = false;
	public static bool irenounce = false;
	public static bool Igame = false;
	public static bool Istop = false;
	private Transform Drop;
	private ZjhPlayer Challenger;
	private ZjhPlayer BeChallenger;
	public static int PlayTurnNum = 0;
	private bool OnFight = false;
	private thirteen.ResRoundOverMsg RoundOver;
	private bool NeedOver = false;
	public static Zjh.ResRestoreMsg restore;
	private int UpNetWordType = 0;
	private GameObject ConfigList = null;
	public GroupCard gourpCard = null;

		// 豹子 同花顺 同花 顺子 对子 散牌
	// Use this for initialization
	void Start () {
		UpBet = 0;
		inZJHGAME = true;
		if (BgmPlayer.onplay != "bg_game") {
			BgmPlayer.play ("bg_game");
		}

		UnknowBtn = transform.GetChild (1).GetComponent<Button> ();
		TimeTxt = transform.GetChild (2).GetComponent<Text> ();
		RoomNum = transform.GetChild (6).GetComponent<Text> ();
		GameNum = transform.GetChild (7).GetComponent<Text> ();
		TurnNum = transform.GetChild (9).GetComponent<Text> ();
		BetNum = transform.GetChild (12).GetComponent<Text> ();

		for( int i = 0 ; i < transform.GetChild (19).childCount ; i++ ){
			list.Add (transform.GetChild (19).GetChild (i).GetComponent<ZjhPlayer> ());
		}

		BetWindow = transform.GetChild (18).gameObject;
		BtnList = transform.GetChild (16).gameObject;
		Drop = transform.GetChild (17).transform;
		ConfigList = GameObject.Find ("Config");
		gourpCard = GameObject.Find ("GroupCard").GetComponent<GroupCard>();

		EventTriggerListener.Get (transform.GetChild (16).GetChild (0).gameObject).onClick = null;
		EventTriggerListener.Get (transform.GetChild (16).GetChild (1).gameObject).onClick = null;
		EventTriggerListener.Get (transform.GetChild (16).GetChild (2).gameObject).onClick = OpenCard;
		EventTriggerListener.Get (transform.GetChild (16).GetChild (3).gameObject).onClick = GoHome;
		EventTriggerListener.Get (ConfigList.transform.GetChild(1).gameObject).onClick = DsibandRoom;
		EventTriggerListener.Get (ConfigList.transform.GetChild(2).gameObject).onClick = ShowSetUp;
		EventTriggerListener.Get (ConfigList).onClick = HideConfig;
		EventTriggerListener.Get (transform.GetChild(0).GetChild(0).gameObject).onClick = ShowFace;
	
		ServerEventDispather.getInstance ().AddEventDispather (ServerEvent.ZJH_GAME_SERVER,ZjhGame);
		ServerEventDispather.getInstance ().AddEventDispather (ServerEvent.OTHER_JOIN_ROOM,OtherJoinRoom);
		ServerEventDispather.getInstance ().AddEventDispather (ServerEvent.CHANGE_ZJH_PLAYER_STATE,PlayerState);
		ServerEventDispather.getInstance ().AddEventDispather (ServerEvent.CHANGE_ZJH_DEALER,StartDealer);
		ServerEventDispather.getInstance ().AddEventDispather (ServerEvent.NEXT_ZJH_DEAL,NextDeal);
		ServerEventDispather.getInstance ().AddEventDispather (ServerEvent.SEE_ZJH_CARD,SeeCardResult);
		ServerEventDispather.getInstance ().AddEventDispather (ServerEvent.RENOUNCE_ZJH_CARD,DiscardResult);
		ServerEventDispather.getInstance ().AddEventDispather (ServerEvent.SAW_ZJH_CARD,OtherLookCard);
		ServerEventDispather.getInstance ().AddEventDispather (ServerEvent.ROUNDOVER_ZJH_CARD,RoundOverResult);
		ServerEventDispather.getInstance ().AddEventDispather (ServerEvent.RESET_ZJH_CARD,Restart);
		ServerEventDispather.getInstance ().AddEventDispather (ServerEvent.CLOSEROOM_ZJH_ALERT,CloseRoomAlert);
		ServerEventDispather.getInstance ().AddEventDispather (ServerEvent.CLOSEROOM_ZJH_CONFRIM,CloseRoomConfrim);
		ServerEventDispather.getInstance ().AddEventDispather (ServerEvent.LEAVEROOM_ZJH_RESULT,LeaveRoomResult);
		ServerEventDispather.getInstance ().AddEventDispather (ServerEvent.CLOSE_ZJH_DISBAND,DisbandClose);
		ServerEventDispather.getInstance ().AddEventDispather (ServerEvent.UPDATE_ZJH_CEDIT,UpdateCedit);
		ServerEventDispather.getInstance ().AddEventDispather (ServerEvent.RECOVERY_ZJH_BOARD, RecoveryBoard);
		ServerEventDispather.getInstance ().AddEventDispather (ServerEvent.OFFINE_ZJH_PLAYER, PlayerOffline);
		ServerEventDispather.getInstance ().AddEventDispather (ServerEvent.ALLOVER_ZJH_VIEW, AllOverShow);
		ServerEventDispather.getInstance ().AddEventDispather (ServerEvent.FACE_ZJH_SHOW, UseZJHFace);
		ServerEventDispather.getInstance ().AddEventDispather (ServerEvent.VOICE_ZJH_SHOW, UseZJHVoice);

		//设置座次
		int MyIndex = 0;
		thirteen.SeatInfo seatinfo = null;
		for( int q = 0 ;  q < UserInfo.room.seats.Count ; q++ ){
			if( UserInfo.room.seats[q].playerId == UserInfo.UserData.id ){
				MyIndex = UserInfo.room.seats [q].order;
				list [0].Id = UserInfo.room.seats [q].playerId;
				list [0].PlayerIndex = UserInfo.room.seats [q].order;
				list [0].setHead (UserInfo.room.seats [q].icon);
				list [0].P_name = UserInfo.room.seats [q].nickName;
				list [0].P_money = UserInfo.room.seats [q].cedit.ToString();
				list [0].None = UserInfo.room.seats [q].ready != 0?true:false;
				PlayTurnNum = UserInfo.room.seats [q].gamed;
				seatinfo = UserInfo.room.seats [q];
			}
		}
	
		for( int g = 0 ; g < list.Count ; g++ ){
			if(UserInfo.room.seats.Count <= g ){
				list [g].CloseSeat (false);
			}
		}

		for( int s = 1 ; s < list.Count ; s++ ){
			if ( list [s].Open ) {
				MyIndex++;

				if( MyIndex >= UserInfo.room.seats.Count ){
					MyIndex = 0;
				}

				list [s].PlayerIndex = MyIndex;
				Debug.Log ("list [s].PlayerIndex:" + list [s].PlayerIndex);
			}
		}

		for( int s = 0 ; s < UserInfo.room.seats.Count ; s++ ){
			if( UserInfo.room.seats [s].playerId != UserInfo.UserData.id ){
				for( int z = 0 ; z < list.Count ; z++ ){
					if(list [z].Open && UserInfo.room.seats [s].order == list [z].PlayerIndex && UserInfo.room.seats [s].playerId != 0 && UserInfo.room.seats [s].playerId != UserInfo.UserData.id){
						list [z].Id = UserInfo.room.seats [s].playerId;
					
						list [z].setHead (UserInfo.room.seats [s].icon);
						list [z].P_name = UserInfo.room.seats [s].nickName;
						list [z].Offline = UserInfo.room.seats [s].online == 0?true:false;
						list [z].P_money = UserInfo.room.seats [s].cedit.ToString();
						list [z].None = UserInfo.room.seats [s].ready != 0?true:false;
					}
				}
			}
		}


		/*
		if( UserInfo.room.gaming != 0){
			Igame = true;

			if ( seatinfo.ready != 0 ) {

				ShowBtnList ();

				for ( int i = 0; i < list.Count; i++) {
					
					if ( list [i].Id != 0 && list [i].None ) {
						list [i].BuildCard ();
					}

					for( int l = 0 ; l < UserInfo.room.seats.Count ; l++ ){

						if( UserInfo.room.seats[l].playerId == list [i].Id  ){

							if (UserInfo.room.seats [l].seeCard != 0) {

								if ( i == 0 ) {

									List<string> cardstr = new List<string> ();

									for( int y = 0 ; y < UserInfo.room.seats [l].cards.Count ; y++ ){
										cardstr.Add (ZJHCards.CheckCard (UserInfo.room.seats [l].cards [y]));
									}

									//list [0].cardListShow (cardstr);

								} else {

								}

							}

							if (UserInfo.room.seats [l].discard != 0) {
								list [i].RenounceCard ();
							}

							if (UserInfo.room.seats [l].discard != 0) {
								list [i].RenounceCard ();
							}

							if (UserInfo.room.seats [l].lose != 0) {
								list [i].CompareFiald ();
							}


						}
					}
				}
			
			} else {
				GameObject.Find ("OtherInGame").transform.localPosition = Vector3.zero;
			}

		}
		*/
		UpNetWordType = GetNetworkReachabilityType ();

		CheckSameIp ();

		gourpCard.SetPlayer (list [0]);
		gourpCard.SetBtn (BtnList.GetComponent<BetBtnControl>());

		InvokeRepeating ("Recovery", 1f, 0f);
		InvokeRepeating ("ChangeTime",1f, 1f);
	}

	public static int GetNetworkReachabilityType()
	{
		 if (Application.internetReachability == NetworkReachability.NotReachable)
	     {
				return 2;
	     }
	     else if (Application.internetReachability == NetworkReachability.ReachableViaLocalAreaNetwork)
	     {
				return 0;
	     }
	     else if (Application.internetReachability == NetworkReachability.ReachableViaCarrierDataNetwork)
	     {
				return 1;
	     }
		return 2;
	}



	private void CheckSameIp(){

		List<string> IpAlert = new List<string>();
		for( int i = 0 ; i < UserInfo.room.seats.Count ; i++ ){
			for( int s = 0 ; s < UserInfo.room.seats.Count ; s++ ){
				if( UserInfo.room.seats[i].playerId != 0 && UserInfo.room.seats[s].playerId != 0 && UserInfo.room.seats[i].playerId != UserInfo.room.seats[s].playerId ){
					if( UserInfo.room.seats[i].ip == UserInfo.room.seats[s].ip ){
						if(!IpAlert.Contains(UserInfo.room.seats [i].nickName)){
							IpAlert.Add (UserInfo.room.seats [i].nickName);
						}

						if(!IpAlert.Contains(UserInfo.room.seats [s].nickName)){
							IpAlert.Add (UserInfo.room.seats [s].nickName);
						}
					}
				}
			}
		}

		if( IpAlert.Count > 1 ){
			string NickNames = "";
			for (int i = 0; i < IpAlert.Count; i++) {
				NickNames += " " + IpAlert [i];
			}

			string warnStr = "本局部分玩家IP相同 他们的昵称为:" + NickNames;
			ServerEventDispather.getInstance ().Add (ServerEvent.ERROR_MSG, warnStr);
		}

	

	}

	private void UseZJHFace(object obj){
		
		Chat.ResTextChatMsg chat = obj as Chat.ResTextChatMsg;


		string ChatType = chat.content.Substring (0, chat.content.IndexOf(','));
		string ChatContent = chat.content.Substring (chat.content.IndexOf(',')+1,  chat.content.Length - (chat.content.IndexOf (',')+1));

		if( ChatType == "1" ){
			for( int i = 0 ; i < list.Count ; i++ ){
				if(chat.playerId == list[i].Id ){
					list [i].SetFace (ChatContent);
				}
			}
		}else{
			
			for( int i = 0 ; i < list.Count ; i++ ){
				if(chat.playerId == list[i].Id ){
					if (ChatType == "2") {
						string fast =  ChatContent.Substring (0, ChatContent.IndexOf(','));
						ChatContent = ChatContent.Substring (ChatContent.IndexOf(',')+1,  ChatContent.Length - (ChatContent.IndexOf (',')+1));
						list [i].SetFastVoice (fast);
						list [i].SetSpeark (ChatContent);
					} else {
						list [i].SetSpeark (ChatContent);
					}
				}
			}
		}



	}

	private void UseZJHVoice(object obj){

		Chat.ResVoiceChatMsg chat = obj as Chat.ResVoiceChatMsg;
		for( int i = 0 ; i < list.Count ; i++ ){
			if(chat.playerId == list[i].Id ){
				list [i].SetVoice (chat.content);
			}
		}
	
	}

	private void AllOverShow(object obj){
		GameObject.Find ("SumUpCalculation").GetComponent<ZJHSumUpCalculation> ().playerList = list;
		GameObject.Find ("SumUpCalculation").GetComponent<ZJHSumUpCalculation> ().Show ();
	}

	private void PlayerOffline(object obj){
		Zjh.ResOfflineMsg offline = obj as Zjh.ResOfflineMsg;

		string offlineName = "";
		for( int i = 0 ; i < list.Count ; i++ ){
			if(list[i].Id == offline.playerId){
				offlineName = list [i].P_name;
				list [i].Offline = true;
			}
		}

		GameObject.Find ("OfflineAlert").transform.GetChild(0).GetChild(0).GetComponent<Text>().text = "<color=#756038>玩家</color><color=#c15208>" + offlineName + "</color><color=#756038>断开了链接,请稍等</color>";
		GameObject.Find ("OfflineAlert").transform.localPosition = Vector3.zero;
		Tweener tweener = GameObject.Find ("OfflineAlert").transform.DOLocalMoveY (300, 2f);
		tweener.onComplete = delegate {
			GameObject.Find ("OfflineAlert").transform.localPosition = new Vector3 (10000, 10000, 0);
		};
	}

	private void Recovery(){
		if(restore == null){
			return;
		}
		Igame = restore.readied != 0 ? true : false;
		UserInfo.room.curRound = restore.curRound;
		for( int i = 0 ; i < list.Count ; i++ ){
			if(list[i].Id == restore.dealer){
				list [i].master = true;
			}

			if(list[i].Id != 0){
				if ( restore.readied != 0 && list[i].None ) {
					list [i].GameIng = true;
				} else {
					list [i].GameIng = false;
				}
			}
		}

		PetAll =  int.Parse(restore.totalBetedChips.ToString());

		if (restore.preDark != 0) {
			UpBet = int.Parse (restore.preBet.ToString ());
		} else {
			UpBet = int.Parse (restore.preBet.ToString ())/2;
		}

		ChangeBetWindow (restore.nextOptPlayer,false);

		if(restore.reqDisbandPlayer != 0){
			GameObject.Find ("DissolutionAlert").GetComponent<ZJHDissolutionAlert> ().ShowView (list,restore.reqDisbandPlayer);
			for( int n = 0 ; n < restore.agreeDisbandPlayers.Count ; n++ ){
				GameObject.Find ("DissolutionAlert").GetComponent<ZJHDissolutionAlert> ().ChangeTypes (restore.agreeDisbandPlayers[n], 1);
			}
		}

		if (restore.betedChipsHistory.Count > 0) {
			for( int l = 0 ; l < restore.betedChipsHistory.Count ; l++ ){
				List<int> tempList = new List<int> ();
				if (restore.betedChipsHistory[l] > 4){
					while (restore.betedChipsHistory[l] > 4) {
						restore.betedChipsHistory[l] = restore.betedChipsHistory[l]-4;
						tempList.Add (4);
					}

					if (restore.betedChipsHistory[l] > 0) {
						tempList.Add ((int)restore.betedChipsHistory[l]);
					}

				}else{
					tempList.Add ((int)restore.betedChipsHistory[l]);
				}
				DropIt (null, tempList,false);
			}
		}

		ZjhView.restore = null;
	}

	private void RecoveryBoard(object obj){
		InvokeRepeating ("Recovery", 1f, 0f);
	}

	private void DsibandRoom(object obj){
		SoundPlayer.play ("7571");
		GSocket.Send (ByteFactory.makeByte (621101, null)); 
	}

	private void ShowSetUp(GameObject go){
		SoundPlayer.play ("7571");
		GameObject.Find ("SetUpView").transform.localPosition = Vector3.zero;
	}

	private void ShowFace(GameObject go){
		SoundPlayer.play ("7571");
		GameObject.Find ("Face").transform.localPosition = Vector3.zero;
	}

	private void CloseRoomAlert(object obj){
		
		Zjh.ResDisbandRoomAbleMsg alertMsg = obj as Zjh.ResDisbandRoomAbleMsg;
		GameObject.Find ("DissolutionAlert").GetComponent<ZJHDissolutionAlert> ().ShowView (list,alertMsg.playerId);
		GameObject.Find ("DissolutionAlert").GetComponent<ZJHDissolutionAlert> ().ChangeTypes (alertMsg.playerId, 1);
	}

	private void CloseRoomConfrim(object obj){
		Zjh.ResConfirmDisbandRoomMsg alertMsg = obj as Zjh.ResConfirmDisbandRoomMsg;
		GameObject.Find ("DissolutionAlert").GetComponent<ZJHDissolutionAlert> ().ChangeTypes (alertMsg.playerId, alertMsg.yes);
	} 

	private void UpdateCedit(object obj){
		Zjh.ResCeditChangeMsg CeditMsg = obj as Zjh.ResCeditChangeMsg;
		for( int i = 0 ; i < list.Count ; i++ ){
			if( list[i].Id == CeditMsg.playerId ){
				list [i].P_money = CeditMsg.cedit.ToString ();
			}
		}
	}


	private void DisbandClose(object obj){
		GameObject.Find ("DissolutionAlert").GetComponent<ZJHDissolutionAlert> ().Close ();
	} 

	private void LeaveRoomResult(object obj){
		
		long Ids = (long)obj;
		if (Ids == UserInfo.UserData.id) {
			JumpToMain ();
		}else{
			for( int i = 0 ; i < list.Count ; i++ ){
				if (list [i].Id == Ids) {
					list [i].ClearPlayer ();
				}
			}
		}
	} 

	private void JumpToMain(){

		ServerEventDispather.getInstance ().removeAll ();
		info.UserInfo.room.roomId = 0;
		SceneManager.LoadScene (2);

	}

	private void Restart(object obj){
		
		turn = 0;

		for(int i = 0;i<Drop.transform.childCount;i++)
		{
			GameObject go = Drop.transform.GetChild(i).gameObject;
			Destroy(go);
		}


		for( int s = 0 ; s < list.Count ; s++ ){
			list [s].ClearTurn ();
		}

	
		for( int p = 0 ; p < info.UserInfo.room.seats.Count; p++ ){
			if( info.UserInfo.room.seats[p].playerId == info.UserInfo.UserData.id ){
				info.UserInfo.room.seats [p].ready = 0;
			}
		}
	}

	private void StartDealer(object obj){
		
		Destroy (GameObject.Find ("OtherInGame"));

		UserInfo.room.curRound++;
		Igame = true;

		thirteen.ResReadyOverMsg readyover = obj as thirteen.ResReadyOverMsg;

		for( int i = 0 ; i < list.Count ; i++ ){

			if( list[i].Id == UserInfo.UserData.id ){
				list [i].setCardList(readyover.cards);
			}

			if( list[i].Id != 0 && list[i].None ){
				list [i].GameIng = true;
			}
		}

		GameObject.Find ("Dealer").GetComponent<ZJHDealer> ().StartDealer(list,readyover);
		SoundPlayer.play ("发牌");


			
		InvokeRepeating ("ShowBtnList", 1.5f, 0f);
		//InvokeRepeating ("InitDropIt", 1f, 0f);

		gourpCard.CheckSpecial ();

		//ChangeBetWindow (overMsg.nextOptPlayerId);
	}

	private void InitDropIt(){
		for( int i = 0 ; i < list.Count ; i++ ){
			if( list[i].Id != 0 && !list[i].Offline ){
				List<int> tempList = new List<int> ();
				PetAll += 1;
				tempList.Add (1);
				DropIt (list [i].transform.GetChild(0), tempList);
			}
		}
	}

	private void ChangeBetWindow(long playerid,bool flag=true){
		
	}

	private void ShowBtnList(){
		BtnList.transform.localPosition = new Vector3 (0, -470, 0);
	}

	private void PlayerState(object evt){
		for ( int s = 0; s < list.Count ; s++ ) {
			if ( list [s].Id == (evt as Zjh.ResReadyMsg).playerId ) {
				 list [s].None = true;
			}
		}
	}

	private void OtherJoinRoom(object evt){

		thirteen.ResOtherEnterRoomMsg info = evt as thirteen.ResOtherEnterRoomMsg;

		bool flag = false;

		for( int i = 0 ; i < list.Count ; i++ ){
			if(info.seat.playerId == list [i].Id){
				list [i].Offline = false;
				flag = true;
			}
		}

		if( flag ){
			return;
		}

		for( int i = 0 ; i < list.Count ; i++ ){
			Debug.Log (list [i].PlayerIndex +" "+i +" "+info.seat.order);
			if ( list [i].PlayerIndex == info.seat.order ) {
				list [i].Id = info.seat.playerId;
				list [i].PlayerIndex = info.seat.order;
				list [i].setHead(info.seat.icon);
				list [i].P_name = info.seat.nickName;
				list [i].P_money = info.seat.cedit.ToString();
				list [i].Open = true;
				break;
			}

		}

		CheckSameIp ();
	}

	private void ZjhGame(object evt){

	}

	private void NextDeal(object evt){
		
	}

	private void SeeCardResult(object obj){
		
	}

	private void DiscardResult(object obj){
		
	}

	private void OtherLookCard(object obj){

	}

	private void RoundOverResult(object obj){
		GameObject.Find ("Config").transform.localPosition = new Vector3 (10000, 0, 0);
		RoundOver = obj as thirteen.ResRoundOverMsg;
		NeedOver = true;
	}

	private void RoundOverHandle(){

		Destroy (GameObject.Find ("OtherInGame"));

		HideBtnList ();

		ZJHDealer.Licening = false;
		Comparer.Clear ();

		for( int f = 0 ; f < RoundOver.items.Count ; f++ ){
			for( int i = 0 ; i < list.Count ; i++ ){
				if(list[i].Id == RoundOver.items[f].playerId){
					list [i].setCompareCard (RoundOver.items [f]);
					max += 3;
					Comparer.Add (list [i]);
				}
			}
		}

		index = 0;
		index2 = 0;

		InvokeRepeating ("startCompare", 3f, 0f);

		//float time = 3f;
		//GameObject.Find ("Settlement").GetComponent<ZjhSettlement> ().msg = RoundOver;
		//GameObject.Find ("Settlement").GetComponent<ZjhSettlement> ().playerList = list;
		//GameObject.Find ("Settlement").GetComponent<ZjhSettlement> ().ShowView (time);

		//InvokeRepeating ("HideBtnList", time, 0f);
	}

	private int index = 0;
	private int index2 = 0;
	private int max = 0;
	private List<ZjhPlayer> Comparer = new List<ZjhPlayer>();

	private void startCompare (){
		InvokeRepeating ("Compare", 1f, 1f);
	}

	private void Compare (){

		Comparer [index2].ShowCard ();

		index2++;
		if ( index2 >= Comparer.Count ) {
			index2 = 0;
		}
		index++;
		if(index >= max){
			CancelInvoke ();
			//InvokeRepeating ("LiceningOver" , 1f , 0f );
			//transform.localPosition = new Vector3 (10000, 0, 0);
		}
	}

	private void HideBtnList(){
		BtnList.transform.localPosition = new Vector3 (0, 10000, 0);
	}
		
	private void OpenCard(GameObject go){
		if(go.GetComponent<Button>().enabled == false){
			return;
		}
		SoundPlayer.play ("7571");
		GSocket.Send(ByteFactory.makeByte(621111,null));
	}

	private void GoHome(GameObject go){
		if(go.GetComponent<Button>().enabled == false){
			return;
		}
		SoundPlayer.play ("7571");
		GSocket.Send(ByteFactory.makeByte(621113,null));
	}

	private void ShowConfig(GameObject go){
		SoundPlayer.play ("7571");
		if (ConfigList.transform.localPosition.x == 0) {
			ConfigList.transform.localPosition = new Vector3 (10000, 0, 0);
			UnknowBtn.gameObject.SetActive (true);
		} else {
			ConfigList.transform.localPosition = Vector3.zero;
			UnknowBtn.gameObject.SetActive (false);
		}
	}

	private void HideConfig(GameObject go){
		SoundPlayer.play ("7571");
		ConfigList.transform.localPosition = new Vector3 (10000, 0, 0);
		UnknowBtn.gameObject.SetActive (true);
	}


	private void DropIt(Transform tf,List<int> l , bool plays = true){
		if (plays) {
			for (int i = 0; i < l.Count; i++) {
				if (l [i] > 0 && tf != null) {
					GameObject prefabs = (GameObject)Resources.Load ("bets/Bet_" + l [i]);
					if (prefabs != null) {
						
						if (tf == null) {
							tf = Drop;
						}
						GameObject bet = (GameObject)Instantiate (prefabs, tf);
						bet.transform.localScale = new Vector3(0.7f,0.7f,1f);
						bet.transform.localPosition = Vector3.zero;

						int x = MyRandom.getRandom (-350, 350);
						int y = MyRandom.getRandom (-90, 90);
						bet.transform.SetParent (Drop);
						bet.transform.DOLocalMove (new Vector3 (x, y, 0), 0.5f);
					}
				}

			}
		} else {
			
			for (int i = 0; i < l.Count; i++) {
				if (l [i] > 0 && Drop != null) {
					GameObject prefabs = (GameObject)Resources.Load ("bets/Bet_" + l [i]);
					if (prefabs != null) {
						if (tf == null) {
							tf = Drop;
						}
						GameObject bet = (GameObject)Instantiate (prefabs,tf);
						bet.transform.localScale = new Vector3(0.7f,0.7f,1f);
						int x = MyRandom.getRandom (-250, 250);
						int y = MyRandom.getRandom (-120, 120);
						bet.transform.SetParent (Drop);
						bet.transform.localPosition = new Vector3 (x, y, 0);
					}
				}
			}
		}
	}

	private void ChangeTime(){
		TimeTxt.text =	DateTime.Now.Hour + ":" + DateTime.Now.Minute;
	}

	void OnDestroy(){ 
		UpBet = 0;
		UpID = 0;
		Ilooked = false;
		Ifaild = false;
		irenounce = false;
		Igame = false;
		PlayTurnNum = 0;
		restore = null;

	}

	int frameIndex = 0;
	// Update is called once per frame
	void Update () {
		
		RoomNum.text = UserInfo.room.roomId.ToString();
		GameNum.text = UserInfo.room.curRound.ToString () + " / " + UserInfo.room.rounds;
		BetNum.text = PetAll.ToString ();

		if (NeedOver) {
			if (!OnFight) {
				RoundOverHandle ();
				NeedOver = false;
			}
		}

	}
}
